<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

</head>

<body>
  <!-- 写一个登录界面，包含用户名和密码和提交按钮 -->
  <form>
    用户名：<input type="text" id="username" name="username"><br>
    密码：<input type="password" id="password" name="password"><br>
    <button onclick="login()" type="button">登录</button>
  </form>
  <script src="axios.min.js"></script>
  <script>
    function login() {
      // 获取用户输入的用户名和密码
      const username = document.querySelector("#username").value
      const password = document.querySelector("#password").value
      const param = new URLSearchParams();
      param.append("username", username);
      param.append("password", password);
      // 发送ajax请求给后端
      axios.post(`http://localhost:8080/login`, param)
        .then(function (res) {
          console.log("请求成功", res)
          if(res.data.code == 200) {
            location.href = "index.html"
          }
          if(res.data.code == 0) {
            alert(res.data.msg)
          }
        })
        .catch(function (err) {
          console.log("请求失败", err)
        })
    }
  </script>
</body>

</html>